Updating a Computer

Fixing a Broken Computer

If you already have Computers from before version 0.11.x, it is very likely that they are “broken”. If they are in .yaml format, the steps to fix them are as follows:

YAML Fixes

  1. Import as normal (from_yaml(...)). You should see a warning saying that an old style import is detected.

  2. If the import succeeds, it means that translation should have worked. Immediately dump this computer to a different file (don’t overwrite the old one yet, in case something goes wrong)

  3. Call generate_cell() on this new object. And copy the output to a new cell.

  4. Your parser may need editing (see section below).

  5. This will create a new computer named new. Save this somewhere safe, it is your new Computer.

Class Fixes

If your Computer is a class, you can make your edits on the original definition.

Change your optional and required objects to Resource.

[1]:
from remotemanager.connection.computers.resource import Resource

# optional(...)
Resource(...)

# required(...)
Resource(..., optional=False)
[1]:
None

parser no longer has to be assigned to _parser, and can be defined right there in the class.

You can take your current function, and define it like you would any other function:

[2]:
from remotemanager import BaseComputer

class computer(BaseComputer):

    def __init__(self, *args, **kwargs):
        super().__init__(args, kwargs)

        self.var = Resource(...)

    def parser(self, resources):
        ...

You should also make the necessary changes as described below.

Parser fixes

Two things have changed with the parsers:

  1. format_time has moved to remotemanager.computers.connection.utils

  2. resources is no longer a dict, so needs to be handled differently

For format_time, you can delete all references to it and add "format": "time" to your time Resource. (See formatting info)

Resources.items()

Now the resources input is a fully fledged Resources object, you can change

for k, v in resources.items(): to for v in resources:

And then any reference to k to v.name.

Added in version 0.11.6.

This is not a requirement, however, since Resources now provides an items() function that behaves identically to the dict form.

Here is a minimal example of a parser:

[3]:
def parser(resources):
    output = []
    for v in resources:
        if v:
            output.append(f"{resources.pragma} --{resource.flag}={resource.value}")
    return output